﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Liang.UI.Enums;

namespace Liang.UI
{
    public interface IExtControl
    {
        /// <summary>
        /// 使用类型
        /// </summary>
        [Category("Ext-扩展属性")]
        [Browsable(true)]
        [Description("控件使用类型")]
        UsingTypeEnum ExtUsingType
        {
            set;
            get;
        }

        /// <summary>
        /// 数据字段名称
        /// </summary>
        [Category("Ext-扩展属性")]
        [Browsable(true)]
        [Description("指向数据库表某个字段")]
        string ExtDataField
        {
            set;
            get;
        }

        /// <summary>
        /// 数据字段名称
        /// </summary>
        [Category("Ext-扩展属性")]
        [Browsable(true)]
        [Description("指向数据库表字段对应的值")]
        string ExtDataValue { set; get; }


        /// <summary>
        /// 数据字段名称
        /// </summary>
        [Category("Ext-扩展属性")]
        [Browsable(true)]
        [Description("追加子查询语句")]
        string ExtDataQuery { set; get; }

        /// <summary>
        /// 查询表达式
        /// </summary>
        [Category("Ext-扩展属性")]
        [Browsable(true)]
        [Description("查询表达式选择")]
        QueryExpressionEnum ExtQueryExpression { get; set; }

        /// <summary>
        /// 清空值
        /// </summary>
        void ClearDataValue();
    }

    public class ExtTextBox : TextBox, IExtControl
    {

        #region IExtControl 成员
        private UsingTypeEnum extUsingType = UsingTypeEnum.Query;
        [Category("Ext-扩展属性")]
        [Browsable(true)]
        [Description("控件使用类型")]
        public UsingTypeEnum ExtUsingType
        {
            get
            {
                return extUsingType;
            }
            set
            {
                extUsingType = value;
            }
        }

        private string extDataQuery;
        [Category("Ext-扩展属性")]
        [Browsable(true)]
        [Description("追加子查询语句")]
        public string ExtDataQuery
        {
            get
            {
                return extDataQuery;
            }
            set
            {
                extDataQuery = value;
            }
        }

        private string extDataField;
        [Category("Ext-扩展属性")]
        [Browsable(true)]
        [Description("指向数据库表某个字段")]
        public string ExtDataField
        {
            get
            {
                return extDataField;
            }
            set
            {
                extDataField = value;
            }
        }

        [Category("Ext-扩展属性")]
        [Browsable(true)]
        [Description("字段值")]
        public string ExtDataValue
        {
            get { return this.Text.ToString(); }
            set { this.Text = value; }
        }


        private QueryExpressionEnum extQueryExpression = QueryExpressionEnum.EQ;
        [Category("Ext-扩展属性")]
        [Browsable(true)]
        [Description("查询表达式选择")]
        public QueryExpressionEnum ExtQueryExpression
        {
            get
            {
                return extQueryExpression;
            }
            set
            {
                extQueryExpression = value;
            }
        }

        public void ClearDataValue()
        {
            this.Text = "";
        }

        #endregion
    }

    public class ExtComBox : ComboBox, IExtControl
    {
        #region IExtControl 成员
        private UsingTypeEnum extUsingType = UsingTypeEnum.Query;
        [Category("Ext-扩展属性")]
        [Browsable(true)]
        [Description("控件使用类型")]
        public UsingTypeEnum ExtUsingType
        {
            get
            {
                return extUsingType;
            }
            set
            {
                extUsingType = value;
            }
        }

        private string extDataQuery;
        [Category("Ext-扩展属性")]
        [Browsable(true)]
        [Description("追加子查询语句")]
        public string ExtDataQuery
        {
            get
            {
                return extDataQuery;
            }
            set
            {
                extDataQuery = value;
            }
        }

        private string extDataField;
        [Category("Ext-扩展属性")]
        [Browsable(true)]
        [Description("指向数据库表某个字段")]
        public string ExtDataField
        {
            get
            {
                return extDataField;
            }
            set
            {
                extDataField = value;
            }
        }

        private QueryExpressionEnum extQueryExpression = QueryExpressionEnum.EQ;
        [Category("Ext-扩展属性")]
        [Browsable(true)]
        [Description("查询表达式选择")]
        public QueryExpressionEnum ExtQueryExpression
        {
            get
            {
                return extQueryExpression;
            }
            set
            {
                extQueryExpression = value;
            }
        }

        [Category("Ext-扩展属性")]
        [Browsable(true)]
        [Description("字段值")]
        public string ExtDataValue
        {
            get { return this.SelectedValue == null ? "" : this.SelectedValue.ToString(); }
            set { this.SelectedValue = value; }
        }

        /// <summary>
        /// 清空值
        /// </summary>
        public void ClearDataValue()
        {
            this.SelectedValue = -1;
        }
        #endregion
    }

    public class ExtCheckBox : CheckBox, IExtControl
    {
        #region IExtControl 成员
        private UsingTypeEnum extUsingType = UsingTypeEnum.Query;
        [Category("Ext-扩展属性")]
        [Browsable(true)]
        [Description("控件使用类型")]
        public UsingTypeEnum ExtUsingType
        {
            get
            {
                return extUsingType;
            }
            set
            {
                extUsingType = value;
            }
        }

        private string extDataQuery;
        [Category("Ext-扩展属性")]
        [Browsable(true)]
        [Description("追加子查询语句")]
        public string ExtDataQuery
        {
            get
            {
                return extDataQuery;
            }
            set
            {
                extDataQuery = value;
            }
        }

        private string extDataField;
        [Category("Ext-扩展属性")]
        [Browsable(true)]
        [Description("指向数据库表某个字段")]
        public string ExtDataField
        {
            get
            {
                return extDataField;
            }
            set
            {
                extDataField = value;
            }
        }

        [Category("Ext-扩展属性")]
        [Browsable(true)]
        [Description("字段值")]
        public string ExtDataValue
        {
            get
            {
                if (this.Checked)
                    return "True";
                else
                    return "False";
            }
            set
            {
                if (value == "True")
                    this.Checked = true;
                else
                    this.Checked = false;
            }
        }

        private QueryExpressionEnum extQueryExpression = QueryExpressionEnum.EQ;
        [Category("Ext-扩展属性")]
        [Browsable(true)]
        [Description("查询表达式选择")]
        public QueryExpressionEnum ExtQueryExpression
        {
            get
            {
                return extQueryExpression;
            }
            set
            {
                extQueryExpression = value;
            }
        }

        /// <summary>
        /// 清空值
        /// </summary>
        public void ClearDataValue()
        {
            this.Checked = false;
        }
        #endregion
    }

    public class ExtDateTimePicker : DateTimePicker, IExtControl
    {
        #region IExtControl 成员
        private UsingTypeEnum extUsingType = UsingTypeEnum.Edit;
        [Category("Ext-扩展属性")]
        [Browsable(true)]
        [Description("控件使用类型")]
        public UsingTypeEnum ExtUsingType
        {
            get
            {
                return extUsingType;
            }
            set
            {
                extUsingType = value;
            }
        }


        private string extDataQuery;
        [Category("Ext-扩展属性")]
        [Browsable(true)]
        [Description("追加子查询语句")]
        public string ExtDataQuery
        {
            get
            {
                return extDataQuery;
            }
            set
            {
                extDataQuery = value;
            }
        }
        private string extDataField;
        [Category("Ext-扩展属性")]
        [Browsable(true)]
        [Description("指向数据库表某个字段")]
        public string ExtDataField
        {
            get
            {
                return extDataField;
            }
            set
            {
                extDataField = value;
            }
        }

        [Category("Ext-扩展属性")]
        [Browsable(true)]
        [Description("字段值")]
        public string ExtDataValue
        {
            get { return this.Value.ToString("yyyy-MM-dd HH:mm:ss"); }
            set { this.Text = value; }
        }


        private QueryExpressionEnum extQueryExpression = QueryExpressionEnum.EQ;
        [Category("Ext-扩展属性")]
        [Browsable(true)]
        [Description("查询表达式选择")]
        public QueryExpressionEnum ExtQueryExpression
        {
            get
            {
                return extQueryExpression;
            }
            set
            {
                extQueryExpression = value;
            }
        }

        /// <summary>
        /// 清空值
        /// </summary>
        public void ClearDataValue()
        {
            this.Value = DateTime.Now;
        }
        #endregion
    }

    public class ExtDataGridViewTextBoxColumn : DataGridViewTextBoxColumn, IExtControl
    {

        #region IExtControl 成员

        public UsingTypeEnum ExtUsingType
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        private string extDataQuery;
        [Category("Ext-扩展属性")]
        [Browsable(true)]
        [Description("追加子查询语句")]
        public string ExtDataQuery
        {
            get
            {
                return extDataQuery;
            }
            set
            {
                extDataQuery = value;
            }
        }
        public string ExtDataField
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string ExtDataValue
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public QueryExpressionEnum ExtQueryExpression
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public void ClearDataValue()
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
